package com.example.springboot.impl;

import com.example.springboot.model.Student;
import com.example.springboot.repository.InMemoryStudentDAO;
import com.example.springboot.service.StudentService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author NardinVN
 */
@Service
@AllArgsConstructor
public class InMemoryStudentServiceImpl implements StudentService {
    // Внедернение зависимости через контсруктор Lombok, можно еще полем @Autowired
    private final InMemoryStudentDAO repository;
    @Override
    public List<Student> findAllStudents() {
        return repository.findAllStudents();
//        return List.of(
//                Student.builder().firstName("Seva").email("v@gmail.com").age(20).build(),
//                Student.builder().firstName("Igor").email("v@gmail.com").age(18).build(),
//                Student.builder().firstName("Oleg").email("v@gmail.com").age(22).build()
//        );
    }

    @Override
    public Student saveStudent(Student student) {
        return repository.saveStudent(student);
    }

    @Override
    public Student findByEmail(String email) {
        return repository.findByEmail(email);
    }

    @Override
    public Student updateStudent(Student student) {
        return repository.updateStudent(student);
    }

    @Override
    public void deleteStudent(String email) {
        repository.deleteStudent(email);
    }
}
